package com.gxl.butt;

import com.alibaba.dubbo.spring.boot.annotation.EnableDubboConfiguration;
import com.robert.kafka.kclient.boot.KClientBoot;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;


/**
 * Spring boot main class which starts spring rest controller in the same
 * package.
 * 
 * @author guo xiaolin
 * @since Aug 21, 2015
 *
 */

@EnableDubboConfiguration
@SpringBootApplication
@ImportResource({"classpath:kafka-application.xml"})
public class KClientApplication extends SpringBootServletInitializer {

	protected static Logger log = LoggerFactory.getLogger(KClientApplication.class);

	public static void main(String[] args) {
		ApplicationContext ctxBackend = SpringApplication.run(
				KClientApplication.class, args);

		System.out.println("应用的名称：" + ctxBackend.getApplicationName());

		String startupTime = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss z")
				.format(new Date(ctxBackend.getStartupDate()));
		log.info("KClient application starts at: " + startupTime);

		System.out.println("KClient application starts at: " + startupTime);
	}
//	public static void main(String[] args) {
//	SpringApplication.run(KClientApplication.class, args);
//}

	@Bean(initMethod = "init")
	public KClientBoot kClientBoot(){
		return new KClientBoot();
	}
	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
		return builder.sources(KClientApplication.class);
	}

}
